<template>
  <treeselect
    v-model="selections"
    :options="deptOptions"
    :show-count="true"
    placeholder="请选择分类"
    @select="feiSelect"
  />
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import { itemTypeTreeselect } from "@/api/wms/itemType";
export default {
  components: { Treeselect },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    size: {
      type: String,
      default: "small",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      deptOptions: [],
    };
  },
  computed: {
    selections: {
      get() {
        return this.value;
      },
      set(v) {
        this.$emit("input", v);
      },
    },
  },
  created() {
    itemTypeTreeselect().then((response) => {
      this.deptOptions = response.data;
    });
  },
  methods: {
    feiSelect(node) {
      // 触发自定义事件，并传递选中项的id和name
      this.$emit("treeselect", { id: node.id, name: node.label });
    },
  },
};
</script>
